package demo4;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-06-17
 * Time: 16:26
 */
class OutClass{
    public int data1 = 7;
    public int data2 = 29;
    public static int data3 = 89;

    public void test(){
        System.out.println("外部类的test方法");
    }
    //静态内部类
    static class InnerClass{
        public int a = 10;
        public static int b = 100;

        public void test2(){
            System.out.println(data3);//访问外部类的静态成员
            //访问外部类的实例成员
            /*
            1.先创建外部类对象
            2.通过外部类对象访问成员
             */
            OutClass outClass = new OutClass();
            System.out.println(outClass.data1);
        }
    }
}
public class Test01 {
    public static void main(String[] args) {
        OutClass.InnerClass innerClass = new OutClass.InnerClass();
        innerClass.test2();
        System.out.println(innerClass.a);//访问实例成员
        System.out.println(OutClass.data3);//访问外部类的静态成员
        OutClass outClass = new OutClass();
        System.out.println(outClass.data1);//访问外部类的实例成员
        System.out.println(OutClass.InnerClass.b);//访问静态内部类的静态成员
    }
}
